package com.ruoyi.swla2.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.swla2.mapper.DeviceMapper;
import com.ruoyi.swla2.domain.Device;
import com.ruoyi.swla2.service.IDeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
/**
 * 设备台账Service业务层处理
 *
 * @author jipf
 * @date 2025-07-24
 */
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements IDeviceService
{
    @Autowired
    private DeviceMapper deviceMapper;

    /**
     * 查询设备台账
     *
     * @param id 设备台账主键
     * @return 设备台账
     */
    @Override
    public Device selectDeviceById(Long id)
    {

        return deviceMapper.selectById(id);
    }

    /**
     * 查询设备台账列表
     *
     * @param device 设备台账
     * @return 设备台账
     */
    @Override
    public List<Device> selectDeviceList(Device device)
    {
        LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(device.getDeviceNum())){
            queryWrapper.eq(Device::getDeviceNum,device.getDeviceNum());
        }
        if(device.getInstallTime() != null){
            queryWrapper.eq(Device::getInstallTime,device.getInstallTime());
        }
        if(StringUtils.isNotBlank(device.getInstallPosition())){
            queryWrapper.eq(Device::getInstallPosition,device.getInstallPosition());
        }
        return deviceMapper.selectList(queryWrapper);
    }

    /**
     * 新增设备台账
     *
     * @param device 设备台账
     * @return 结果
     */
    @Override
    public int insertDevice(Device device)
    {
        return deviceMapper.insert(device);
    }

    /**
     * 修改设备台账
     *
     * @param device 设备台账
     * @return 结果
     */
    @Override
    public int updateDevice(Device device)
    {
        device.setUpdateTime(DateUtils.getNowDate());
        return deviceMapper.updateById(device);
    }

    /**
     * 批量删除设备台账
     *
     * @param ids 需要删除的设备台账主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteDeviceByIds(Long[] ids)
    {
        return deviceMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除设备台账信息
     *
     * @param id 设备台账主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteDeviceById(Long id)
    {
        return deviceMapper.deleteById(id);
    }
}
